package com.azunitech.intercpt.ejb;

import java.util.Arrays;
import java.util.concurrent.atomic.AtomicInteger;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.ejb.PostActivate;
import javax.interceptor.AroundInvoke;
import javax.interceptor.InvocationContext;

import org.apache.log4j.Logger;

public class ContextInterceptor {
	private static Logger logger = Logger.getLogger(ContextInterceptor.class);
	private static AtomicInteger index = new AtomicInteger();
	
	@AroundInvoke
	public Object context(InvocationContext ic) throws Exception {
		 try {
			 int i = index.incrementAndGet();
			 Object[] params = ic.getParameters();
			 logger.info(Arrays.toString(params) + " " + params.length);
			 ic.getContextData().put("SOME_KEY", "called");
			 return ic.proceed();
		 }
		 finally{
		 }
	}
}
